package com.token.sysflow.action;

import com.token.base.AgentAction;
import com.token.base.FuncUtil;
import com.token.base.Pl;
import com.token.sql.IntegrateSql;
import com.token.sysflow.impl.AbstractFlowHandlerImpl;
import com.token.sysflow.core.FlowHandlerService;
import lombok.Setter;

/**
 * @author chenjianxiong 2020/4/12
 */
public abstract class AbstractFlowAction implements AgentAction {
    @Setter
    private boolean needOpinion = false;
    public void executeAction(FuncUtil f) throws Exception{

    }

    /**
     *
     * @param f
     * @param handler
     * @throws Exception
     */
    protected void publicParameter(FuncUtil f,AbstractFlowHandlerImpl handler) throws Exception{
        String key = f.getUrlQueryString("keyUnid",true,"单据关联Id");
        handler.setKeyUnid(key);
        handler.setActionTimer(Pl.getCurDataTime());
        handler.setActionUser(f.getEffectiveUserName());
        handler.setSysId(Pl.getSysId());
        if(needOpinion){
            handler.setOpinions(f.getUrlQueryString("opinions",true,"意见"));
        }else{
            handler.setOpinions(f.getUrlQueryString("opinions"));
        }

    }

    /**
     *
     * @param f 类型
     * @param iSql
     * @param handler
     * @throws Exception
     */
    public void start(FuncUtil f,IntegrateSql iSql,AbstractFlowHandlerImpl handler) throws Exception{
//        f.initStartTime();
        this.publicParameter(f,handler);
        FlowHandlerService service = new FlowHandlerService(iSql);
        service.execute(handler);
        f.setJsonData(handler.getResult());
//        f.printRunTime("提交结束");
    }
}
